package emulator.hardware.memory;

import java.util.Arrays;

import emulator.hardware.debug.BusWatchException;

public class CountingMemoryBlock extends MemoryBlock {
	int[] read_counter;
	int[] write_counter;

	public CountingMemoryBlock(int size) {
		super(size);
		read_counter = new int [size];
		write_counter = new int [size];
		resetCounter();
	}
	
	public void resetCounter() {
		Arrays.fill(read_counter, 0);
		Arrays.fill(write_counter, 0);
	}

	@Override
	public int read(int address) throws UnmappedMemoryException,
			BusWatchException {
		read_counter[address]++;
		return super.read(address);
	}

	@Override
	public void write(int address, int data) throws UnmappedMemoryException,
			BusWatchException {
		write_counter[address]++;
		super.write(address, data);
	}

	public int [] getReadCounter() { return read_counter; } 
	public int [] getWriteCounter() { return write_counter; }

	public boolean wasWritten(int address) {
		return write_counter[address] > 0;
	} 
}
